﻿package org.demo.book;

import org.demo.book.BookImage;
import android.graphics.Point;

/**
 * Description: 书架的书籍对象,使用BookImage类
 * <br/>site: <a href="http://weibo.com/u/1679839007">nonoob</a> 
 * <br/>Copyright (C), 1989-2011, Hongxu Chen
 * <br/>This program is protected by copyright laws.
 * <br/>Program Name:
 * <br/>Date:2011-11-15
 * @author  Hongxu Chen leftcopy.chx@gmail.com
 * @version  1.0
 */
public class BookInstance
{
	// 保存书的所对应的图片
	private BookImage image;
	// 该书的左上角的x坐标
	private int beginX;
	// 该书的左上角的y坐标
	private int beginY;
	// 该书在BookInstance[][]数组中第一维的索引值
	private int indexX;
	// 该对象在BookInstance[][]数组中第二维的索引值
	private int indexY;

	// 只设置该BookInstance对象在数组中的索引值
	public BookInstance(int indexX , int indexY)
	{
		this.indexX = indexX;
		this.indexY = indexY;
	}

	public int getBeginX()
	{
		return beginX;
	}

	public void setBeginX(int beginX)
	{
		this.beginX = beginX;
	}

	public int getBeginY()
	{
		return beginY;
	}

	public void setBeginY(int beginY)
	{
		this.beginY = beginY;
	}

	public int getIndexX()
	{
		return indexX;
	}

	public void setIndexX(int indexX)
	{
		this.indexX = indexX;
	}

	public int getIndexY()
	{
		return indexY;
	}

	public void setIndexY(int indexY)
	{
		this.indexY = indexY;
	}
	

	public BookImage getImage()
	{
		return image;
	}

	public void setImage(BookImage image)
	{
		this.image = image;
	}

	// 获取该BookInstance的中心,首+尺寸的一半
	public Point getCenter()
	{
		return new Point(getImage().getImage().getWidth() / 2
			+ getBeginX(), getBeginY()
			+ getImage().getImage().getHeight() / 2);
	}	
	// 判断两个BookInstance上的图片是否相同
	public boolean isSameImage(BookInstance other)
	{
		if (image == null)
		{
			if (other.image != null)
				return false;
		}
		// 只要BookInstance封装图片ID相同，即可认为两个Piece相等。
		return image.getImageId() == other.image.getImageId();
	}
}
